package com.bluetoothsms.x86;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class LogDialog extends JDialog {

	private static final long serialVersionUID = 1L;

	private final Component mParent;
	private final JTextArea mTextArea;

	/**
	 * Create the dialog.
	 */
	public LogDialog(Component parent, Image icon) {
		mParent = parent;

		setType(Type.POPUP);
		setModal(true);
		setModalityType(ModalityType.APPLICATION_MODAL);
		setTitle("Log");
		setBounds(100, 100, 450, 300);
		setIconImage(icon);
		getContentPane().setLayout(new BorderLayout());

		mTextArea = new JTextArea();
		mTextArea.setEditable(false);

		JScrollPane scrollPane = new JScrollPane(mTextArea);
		getContentPane().add(scrollPane, BorderLayout.CENTER);

		JButton btnClose = new JButton("Schliessen");
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
			}
		});
		btnClose.setFont(new Font("Tahoma", Font.PLAIN, 18));
		getContentPane().add(btnClose, BorderLayout.SOUTH);
	}

	@Override
	public void setVisible(boolean b) {
		if (b)
			setLocationRelativeTo(mParent);

		super.setVisible(b);
	}

	public void append(String text) {
		mTextArea.append(text + '\n');
		mTextArea.setCaretPosition(mTextArea.getDocument().getLength());
	}

}
